import React from 'react';
import {Link} from 'react-router';
import {Icon, Message} from 'antd';
import {formatDateBetween, formatDateWithCh, formatDate} from '../../utils';
import config from '../../config';
/**
 * 加载公共组件
 * */
import MainSection from '../../components/MainSection/MainSection';
import Panel from '../../components/Panel/Panel';


/**
 * 加载样式或图片文件
 * */
import './sass/applySuccess.scss';
import iconSuccess from '../_common_img/signSuccess/success.png';


class ApplySuccess extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            order: {
                number: 0,
                price: 0,
                payPrice: 0,
                point: 0,
                payPoint: 0,
                orderTime: 0,
                payMethod: 101,
                childCount: 0
            },
            // curAct: {
            //     room: {},
            //     sponsor: {}
            // }
        };
    }

    componentWillMount() {
        const {location, actions} = this.props;
        actions.fetchOrderDetail({eventId: location.state.eventId}).then(res => {
            console.log(res);
            if (res.data.code === 20000) {
                this.setState({
                    order: res.data.data
                })
            } else {
                Message.warn(res.data.message);
            }
        });

        // actions.fetchActListDetailPerson( location.state.eventId).then(res => {
        //     if (res.data.code === 20000) {
        //         this.setState({
        //             curAct: res.data.data
        //         });
        //     } else {
        //         Message.warn(res.data.message);
        //     }
        // });
    }

    render() {
        const {user } = this.props;
        let order = this.state.order;
        // let curAct = this.state.curAct;
        let isScore = order.payMethod === 103;
        // let childNum = isScore ? (order.payPoint / order.point) : (order.payPrice / order.price);
        let price = isScore ? (order.point + '积分') : ('¥ ' + order.price / 100);
        let payPrice = isScore ? (order.payPoint + '积分') : ('¥ ' + order.payPrice / 100);
        return (
            <MainSection className="apply-success">
                <div className="act-head">
                    <div className="success-text">
                        <img src={iconSuccess} alt=""/>
                        <p className="title">恭喜您报名成功</p>
                    </div>
                    <div className="btn-group">
                        <Link class="btn-order" to="/userCenter/actMan">查看订单</Link>
                        <Link class="btn-list" to="/activityList">返回活动列表</Link>
                    </div>
                </div>
                <Panel title='订单明细' className="act-body">
                    <div className="sub-title">
                        <span>报名电话</span> <em>{user.userInfo.phone}</em>
                    </div>
                    <p><span>儿童人数</span><em>{order.childCount}</em></p>
                    <p><span>活动单价</span><em>{price}</em></p>
                    <p><span>实付总价</span><em
                        class="color-orange">{payPrice}</em></p>
                    <p><span>订单编号</span><em>{order.number}</em></p>
                    <p><span>订单时间</span><em>{formatDate(order.orderTime,true)}</em></p>
                    <p><span>支付方式</span><em>{config.PAY_TYPE[order.payMethod]}</em></p>
                </Panel>
            </MainSection>
        );
    }
}

export default ApplySuccess;